#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int cmp(const void* e1, const void* e2) {
	return *(int*)e1 - *(int*)e2;
}
void swap(char*i,char*j,int width){
	for (int k = 0; k < width; k++) {
		char t = *(i+k);
		*(i + k) = *(j + k);
		*(j + k) = t;}}
void copy(char* d,char*s, int width) {
	for (int i = 0; i < width; i++)
		*(d + i) = *(s + i);}
void qsort(void* base, int sz, int width, int (*cmp)(const void* e1, const void* e2)) {
	if (sz <= 1)return;
	int i = -1, j = sz;
	char mid[1000] = { 0 };
	copy(mid, (char*)base + (i + j >> 1) * width,width);
	while (i < j) {
		do i++; while (cmp((char*)base + i * width, mid) < 0);
		do j--; while (cmp((char*)base + j * width, mid) > 0);
		if (i < j) swap((char*)base + i * width, (char*)base + j * width, width); 
	}
	qsort(base, j+1, width, cmp);
	qsort((char*)base +( j + 1)*width, sz-j-1, width, cmp);
}
int main() {
	int a[10] = { 49, 59, 88, 37, 98, 97, 68, 54, 31, 3 };
	char b[2][5] = {"hehe","haha"};
	qsort(a, 10, 4, cmp);
	for (int i = 0; i < 10; i++)printf("%d ", a[i]);
	printf("\n");
	qsort(b, sizeof(b) / sizeof(b[0]),sizeof(b),stringcmp);
	printf("%s\n%s", b[0], b[1]);
	return 0;
}